<template>
	<view class="container" :style="'min-height:' +pageHei+';'">
		<!-- #ifdef H5 -->
			<u-sticky :customNavHeight="0">
				<view class="u-flex u-p-y-10" style="background-image: linear-gradient(180deg, #4e9ce6 100%, #f7f8fc 50%);">
					<image class="u-m-x-20" v-if="windowUrl" @click="$store.commit('toWindowUrl')"
						src="https://job.ydylmold.cn/image/home-fill.png" style="width: 50rpx;" mode="widthFix">
					</image>
				</view>
			</u-sticky>
		<!-- #endif -->
		<view class="u-p-x-30 u-p-y-30">
			<!-- 搜索框 -->
			<view class="searchBox u-m-t-30 u-m-b-56 u-flex u-row-between" style="background-color: #1DA9FF;">
				<view class="searchtext">
					<text class="stext huFamily"> 人脉搜索 </text>
				</view>
				<view class="b-rr-44 u-font-24 u-weight-500 u-flex"
					style="width: 430rpx;height: 74rpx;background-color: white;margin-right: 6rpx;">
					<u--input @confirm="queryFriends" v-model="searchText" placeholder="输入昵称, 企业, 行业等"
						placeholderStyle="fontSize:28rpx;color:#a8a8a8;"></u--input>
						<view class="u-m-r-20" @click="queryFriends">
							<u-icon name="search" color="#666666" size="24"></u-icon>
						</view>
				</view>
			</view>
			<!-- 个人 -->
			<view v-if="version == 1" class="box-list">
				<view class="box-item" v-for="(item,index) in acList" :key="index">
					<my-card @clickCard="toUrl" @rightCilck="rightCilckBtn" :acIndex="index"
						leftText="极速联系" rightText="发消息" acWidth="320rpx" :acItem="item.usrCraftsman">
					</my-card>
				</view>
			</view>
			<!-- 企业 -->
			<view v-else class="box-list">
				<view class="box-item" v-for="(item,index) in acList" :key="index">
					<my-card @clickCard="toUrl" @rightCilck="rightCilckBtn" :acIndex="index"
						leftText="极速联系" rightText="发消息" acWidth="320rpx" :acItem="item.usrCompany">
					</my-card>
				</view>
			</view>
		</view>
		<my-empty tipText="好友不在线哦" image="http://cdn.uviewui.com/uview/empty/data.png" v-if="isEmpty"></my-empty>
		<u-loadmore :status="status" v-else></u-loadmore>
		<my-auth-modal></my-auth-modal>
		<view class="top-box" @click="scrollTop = 0">
			<u-back-top :scroll-top="scrollTop" top="600"></u-back-top>
		</view>
	</view>
</template>
<script>
	import {
		morningAfternoon
	} from '@/utils/formaterTime.js'
	import {
		getToken,
		setToken
	} from '@/utils/token.js'
	import {
		duplicateRemoval
	} from '@/utils/common.js'
	import {
		queryFriends
	} from '@/common/api/msg.js'
	import store from '@/store/index.js'
	export default {
		data() {
			return {
				itemArr: [],
				list3: [],
				paymentMethodShow: false,
				descShow: false,
				
				//类型选项配置
				pageHei: '100vh',
				currPage: 1,
				acList: [],
				allpage: 1,
				isEmpty: false,
				status: 'loading',
				searchText: '',
				jobList: [],
				showHyText: '',
				acHyText: '',
				showAddr: '',
				//查询条件
				form: {
					address: '',
					hyText: ''
				},
				version: getToken('version'),
				showSear: false,
				freshTime: null,
				windowUrl: getToken('windowUrl'),
				scrollTop:0
			}
		},
		onReachBottom: function() {
			if (this.status == 'loadmore') {
				this.currPage++
				this.queryFriends()
			}
		},
		// 触发下拉刷新
		onPullDownRefresh() {
			this.getNewList()
			// 延迟关闭刷新动画
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onNavigationBarButtonTap(e) {
		},
	
		onLoad: function() {
			uni.getSystemInfo({
				success: (res) => {
					this.pageHei = res.windowHeight * 2 + 'rpx'
				}
			})
			this.queryFriends()
		},
		onShow: function() {
			// if(getToken('AUTH_TYPE'))
			// 	store.state.user.authType = getToken('AUTH_TYPE');
			if (this.version != getToken('version')) {
				this.getNewList()
				this.version = getToken('version')
			}
			this.$store.dispatch('getUnReadListByEntity')
			this.getUnRead()
			uni.showTabBar()
		},
		onPageScroll(e){
			this.scrollTop = e.scrollTop
		},
		methods: {
			morningAfternoon,
			getUnRead() {
				this.freshTime = setTimeout(() => {
					this.$store.dispatch('getUnReadListByEntity')
					this.getUnRead()
				}, 30000)
			},
			closeSear() {
				this.showSear = !this.showSear
				this.searchText = ''
				this.searchItem()
			},
			toUrl(data) {
				this.$store.commit('toUserIndex', data.item)
			},
			toNavaUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
			rightCilckBtn(data) {
				uni.navigateTo({
					url: `/pages/comment/chat/index?useNum=${getToken('version') == 1? (data.item && data.item.craftsmanId): (data.item && data.item.companyId)}`
				});
			},
			
			getNewList() {
				this.currPage = 1
				this.acList = []
				this.queryFriends()
			},
			searchItem() {
				this.getNewList()
			},
			queryFriends() {
				this.status = 'loading'
				this.acList=[]
				let paras = {
					userId: getToken('useNum'),
					friendTypeId: getToken('version') == 1 ? 0 : 1,
					status: 1,
					searchText: this.searchText,
					industryTypeName: this.form.hyText,
					cityName: this.form.address,
					'page.current': this.currPage,
					friendsType: 0,
					lat: 1,
					lng: 1
				};
				console.log('paras', paras)
				queryFriends(paras).then(res => {
					if (res.data) {
						this.acList = duplicateRemoval(this.acList, res.data && res.data && res.data.rows || [],
							'firendId')
						//console.log(this.acList,8888)
						this.allpage = res.data && res.data.total
						this.currPage < this.allpage ? this.status = 'loadmore' : this.status = 'nomore'
						this.isEmpty = this.acList.length == 0 ? true : false
						this.acList.forEach(m => {
							if (m.usrCraftsman && m.usrCraftsman['usrName']) {
								m.acName = m.usrCraftsman['usrName']
							} else {
								m.acName = m.usrCompany && m.usrCompany['companyNameCn'] || ''
							}
						})
						
					}
				})
			},
			//地址选择回调处理
			handleChangeAddress(data) {
				let arr = data.detail.value.map(s => s.text)
				this.showAddr = arr && arr.length && arr[arr.length - 1] || ''
				this.form.address = this.showAddr
				this.getNewList()
			},
			handleChangeHy(data) {
				let arr = data.detail.value.map(s => s.text)
				this.form.hyText = arr.join(' ')
				this.showHyText = arr && arr.length && arr[arr.length - 1] || ''
				this.getNewList()
			}
		}
	}
</script>
<style lang="scss" scoped>
	.list-cell {
		display: flex;
		box-sizing: border-box;
		width: 100%;
		padding: 10px 24rpx;
		overflow: hidden;
		color: #323233;
		font-size: 14px;
		line-height: 24px;
		background-color: #fff;
	}

	.huFamily {
		font-family: '胡晓波男神体';
	}

	.container {
		background: linear-gradient(180deg, rgba(78, 156, 230, 1) 0%, rgba(247, 248, 252, 1) 100%);
	}

	.searchBox {
		height: 82rpx;
		border-radius: 44rpx;
		align-items: center;

		.searchtext {
			margin-left: 32rpx;
			font-size: 48rpx;
			font-weight: 400;
			color: rgba(255, 255, 255, 1);

			.stext {
				text-shadow: 0rpx 6rpx 10rpx 0rpx rgba(0, 0, 0, 0.25);
			}
		}
	}

	.box-list {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: center;
		margin-top: 20rpx;
	}

	.down {
		height: 100%;
		position: relative;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		align-items: center;
		flex-wrap: nowrap;

		.menu_type {
			height: 80rpx;

			.title {
				height: 100%;
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
				font-size: 30rpx;
				color: #666;
			}
		}
	}
</style>
